const express = require('express')

const {
	addTeam,
	listTeam,
	updateTeam,
	teamUserList,
	teamOtherUser,
} = require('../modules/module-team')

const router = express.Router()

// /ult/team/list
router.post('/team/list', function(req, res, next) {
	let {
		user_id,
		user_role,
	} = req.body
	listTeam(user_id, user_role).then(result => {
		res.type('json').send(result)
	})
})

// /ult/team/edit
router.post('/team/edit', function(req, res, next) {
	let params = req.body
	if (params.flag == 'add') {
		return addTeam(params).then(result => {
			res.type('json').send(result)
		})
	}
	return updateTeam(params).then(result => {
		res.type('json').send(result)
	})
})

// /ult/team/user/list
router.post('/team/user/list', function(req, res, next) {
	let teamId = req.body.teamId
	teamUserList(teamId).then(result => {
		res.type('json').send(result)
	})
})

// /ult/team/user/other
router.post('/team/user/other', function(req, res, next) {
	let {
		teamId,
		userId,
	} = req.body || ''
	teamOtherUser(teamId, userId).then(result => {
		res.type('json').send(result)
	})
})

module.exports = router